package com.hzhr.iot.user.dao;

import com.hzhr.iot.user.dao.mapper.custom.ResourceInActionEntityCustomMapper;
import com.hzhr.iot.user.dao.mapper.generator.ResourceInActionEntityMapper;
import com.hzhr.iot.user.entity.ResourceInActionEntity;
import com.hzhr.iot.user.entity.ext.ResourceInActionEntityExt;
import com.hzhr.iot.user.queryModel.custom.ResourceInActionCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ResourceInActionDao {
    @Autowired
    ResourceInActionEntityMapper resourceInActionEntityMapper;
    @Autowired
    ResourceInActionEntityCustomMapper resourceInActionEntityCustomMapper;

    public int insert(ResourceInActionEntity record) {
        if (record == null) return 0;
        int changeCount = resourceInActionEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(ResourceInActionCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = resourceInActionEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(ResourceInActionEntity record) {
        if (record == null) return 0;
        int changeCount = resourceInActionEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(ResourceInActionCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = resourceInActionEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public ResourceInActionEntity selectEntity(ResourceInActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceInActionEntityExt> extList = resourceInActionEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ResourceInActionEntity> selectEntityList(ResourceInActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceInActionEntityExt> extList = resourceInActionEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<ResourceInActionEntity> entityList = new ArrayList<>();
        for (ResourceInActionEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ResourceInActionEntityExt selectExt(ResourceInActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceInActionEntityExt> extList = resourceInActionEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ResourceInActionEntityExt> selectExtList(ResourceInActionCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ResourceInActionEntityExt> extList = resourceInActionEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(ResourceInActionCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = resourceInActionEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
